package com.aabbc.camel.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.Instant;

/**
 * TestController
 *
 * @author: <a href="mailto:chenfenghai@oristartech.com">chenfenghai</a>
 * @version: 1.0
 * @date: 2019-12-02 17:25
 */
@Slf4j
@RestController
public class TestController {

    @Produce(value = "direct:in")
    protected ProducerTemplate template;

    @GetMapping("/test")
    public String test(){
        return "TestController.test" + Instant.now().toEpochMilli();
    }

    @PostMapping("/send")
    public String send(@RequestBody String message){
        log.info("message: {}", message);
        template.sendBody(template.getDefaultEndpoint(), message);
        return "success " + Instant.now().toEpochMilli();
    }
}
